/*
 * @Author: your name
 * @Date: 2021-08-02 00:14:12
 * @LastEditTime: 2021-08-12 10:04:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \aircityinit\src\router\index.js
 */
import Vue from "vue";
import Router from "vue-router";
import VueRouter from "vue-router";

// 引入路由模块
import { TagPageRoute } from "./modules/tagpages";
import { AdministrationRoute } from "./modules/administration";


Vue.use(VueRouter);

//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)

   }

const routes = [
  {
    path: "/",
    redirect: "home",
  },
  {
    path: "/home",
    name: "home",
    component: () =>
      import(/* webpackChunkName: "home" */ "@/views/Home/Home.vue"),
      children:[
        {
          path: "mockc",
          name: 'mockc',
          component: resolve => require(['@/views/Home/mockc/mockc.vue'],resolve)
        },
        {
          path: "mock1",
          name: 'mock1',
          component: resolve => require(['@/views/Home/mockc/mock1.vue'],resolve)
        },
      ]
  },
  // 在此插入路由模块
  TagPageRoute,
  AdministrationRoute,
  {
    path: "/404",
    name: "NotFound",
    component: () =>
      import(/* webpackChunkName: "notFound" */ "@/views/404/index.vue"),
  },
  {
    path: "*", //处理错误页面
    redirect: "/404",
  },
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});
// 添加路由守卫
// router.beforeEach((to, from, next) => {
//   // 可以添加登录前的导航守卫

//   console.log('to:', to);
//   console.log('from:', from);
//   next()
// })
export default router;
